﻿using MediatR;
using SlaughterItem.Common.Domains.Warehouse;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.POOK.DepotData
{
    /// <summary>
    /// 显示仓库表数据
    /// </summary>
    public class ShowDepotDataHandler : IRequestHandler<ShowDepotDataCommand, Result>
    {
        public ShowDepotDataHandler(IBaseRepositoryGet<DepotType> depotTypeRepository)
        {
            DepotTypeRepository = depotTypeRepository;
        }

        public IBaseRepositoryGet<DepotType> DepotTypeRepository { get; set; }
        public async Task<Result> Handle(ShowDepotDataCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCode.Search};
            var list = DepotTypeRepository.GetAll().Where(x=>x.IsDepotType==false).ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
